import request from '@/utils/request'

// 登录请求参数类型
export interface LoginParams {
  account: string
  password: string
  tenantId?: string
  loginType: 'platform' | 'tenant'
}

// 登录响应类型
export interface LoginResponse {
  token: string
  user: {
    id: string
    name: string
    username: string
    email: string
    avatar?: string
    role: 'admin' | 'user' | 'tenant'
    permissions: number[]
    createdAt: string
    updatedAt: string
  }
}

// 登录
export const login = (params: LoginParams) => {
  return request.post<LoginResponse>('/auth/login', params) as unknown as Promise<LoginResponse>
}

// 退出登录
export const logout = () => {
  return request.post('/auth/logout') as unknown as Promise<void>
}

// 获取当前用户信息
export const getCurrentUser = () => {
  return request.get<{
    id: string
    name: string
    username: string
    email: string
    avatar?: string
    role: 'admin' | 'user' | 'tenant'
    permissions: number[]
    createdAt: string
    updatedAt: string
  }>('/auth/current-user') as unknown as Promise<{
    id: string
    name: string
    username: string
    email: string
    avatar?: string
    role: 'admin' | 'user' | 'tenant'
    permissions: number[]
    createdAt: string
    updatedAt: string
  }>
}
